using System.Collections.Generic;
using RMH.DataAccess;

namespace RMH.Services
{
    public abstract class BaseRepositoryBackedService<TServiceEntity, TRepositoryType> : IBaseService<TServiceEntity>
        where TRepositoryType : IRepository<TServiceEntity>
    {
        protected TRepositoryType _repository;

        protected BaseRepositoryBackedService(TRepositoryType repository)
        {
            _repository = repository;
        }
        
        public virtual void Evict(TServiceEntity entity)
        {
            _repository.Evict(entity);
        }

        public virtual TServiceEntity Get(int id)
        {
            return _repository.GetByID(id);
        }

        public virtual void Save(TServiceEntity entity)
        {
            _repository.Save(entity);
            _repository.Flush(); // todo: consider not flushing?
        }

        public IList<TServiceEntity> GetAll()
        {
            return _repository.GetAll();
        }

    }
}